﻿//-----------------------------------------------------------------------
// <author>Paul Long</author>
//-----------------------------------------------------------------------

namespace TopUserCharts
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    /// <summary>
    /// Determines the type of graph that we will create.  This is
    /// based on the types of addresses, ipv4, ipv6, ethernet, that
    /// we are displaying.
    /// </summary>
    public enum GraphType
    {
        /// <summary>
        /// Single Row Bar chart.
        /// </summary>
        SingleBar,

        /// <summary>
        /// Double Row Bar chart.
        /// </summary>
        DoubleBar,

        /// <summary>
        /// Triple Row Bar chart.
        /// </summary>
        TripleBar
    }
    
    /// <summary>
    /// BarChart class to create the bar chart.
    /// </summary>
    public partial class BarChart : Form
    {
        /// <summary>
        /// Holds the Y values for a single column bar chart.
        /// </summary>
        private double[] yaxisValues;

        /// <summary>
        /// Holds the X values for a single column bar chart.
        /// </summary>
        private string[] xaxisValues;

        /// <summary>
        /// Holds the T values for a double column bar chart.
        /// </summary>
        private double[] yaxisValues2;

        /// <summary>
        /// Holds the X values for a double column bar chart.
        /// </summary>
        private string[] xaxisValues2;

        /// <summary>
        /// Holds the Y values for a triple column bar chart.
        /// </summary>
        private double[] yaxisValues3;

        /// <summary>
        /// Holds the X values for a triple column bar chart.
        /// </summary>
        private string[] xaxisValues3;

        /// <summary>
        /// Holds the type of graphs, single, double, or triple row bar chart.
        /// </summary>
        private GraphType graphType;

        /// <summary>
        /// Initializes a new instance of the BarChart class.
        /// Creates a Bar Chart with one row.
        /// </summary>
        /// <param name="inYValues">Provided Y values</param>
        /// <param name="inXValues">Provided X values</param>
        public BarChart(double[] inYValues, string[] inXValues)
        {
            this.graphType = GraphType.SingleBar;
            this.xaxisValues = inXValues;
            this.yaxisValues = inYValues;

            this.InitializeComponent();
        }

        /// <summary>
        /// Initializes a new instance of the BarChart class.
        /// Creates a bar chart with two rows.
        /// </summary>
        /// <param name="inYValues">Provided Y values</param>
        /// <param name="inXValues">Provided X values</param>
        /// <param name="inYValues2">Provided Y values second row</param>
        /// <param name="inXValues2">Provided X values second row</param>
        public BarChart(double[] inYValues, string[] inXValues, double[] inYValues2, string[] inXValues2)
        {
            this.graphType = GraphType.DoubleBar;

            this.xaxisValues = inXValues;
            this.yaxisValues = inYValues;
            this.xaxisValues2 = inXValues2;
            this.yaxisValues2 = inYValues2;

            this.InitializeComponent();
        }

        /// <summary>
        /// Initializes a new instance of the BarChart class.
        /// Creates a bar chart with 3 rows.
        /// </summary>
        /// <param name="inYValues">Provided Y values</param>
        /// <param name="inXValues">Provided X values</param>
        /// <param name="inYValues2">Provided Y values second row</param>
        /// <param name="inXValues2">Provided X values second row</param>
        /// <param name="inYValues3">Provided Y values thrid row</param>
        /// <param name="inXValues3">Provided X values thrid row</param>
        public BarChart(double[] inYValues, string[] inXValues, double[] inYValues2, string[] inXValues2, double[] inYValues3, string[] inXValues3)
        {
            this.graphType = GraphType.TripleBar;

            this.xaxisValues = inXValues;
            this.yaxisValues = inYValues;
            this.xaxisValues2 = inXValues2;
            this.yaxisValues2 = inYValues2;
            this.xaxisValues3 = inXValues3;
            this.yaxisValues3 = inYValues3;

            this.InitializeComponent();
        }

        /// <summary>
        /// Loads the bar chart and initalizes the data.
        /// </summary>
        /// <param name="sender">The Sender</param>
        /// <param name="e">The event argument.</param>
        private void BarChart_Load(object sender, EventArgs e)
        {
            if (this.graphType == GraphType.SingleBar)
            {
                this.chart1.Series["Ethernet"].Points.DataBindXY(this.xaxisValues, this.yaxisValues);
            }
            else if (this.graphType == GraphType.DoubleBar)
            {
                this.chart1.Series["Ethernet"].Points.DataBindXY(this.xaxisValues, this.yaxisValues);
                this.chart1.Series["IPv4"].Points.DataBindXY(this.xaxisValues2, this.yaxisValues2);
            }
            else
            {
                this.chart1.Series["Ethernet"].Points.DataBindXY(this.xaxisValues, this.yaxisValues);
                this.chart1.Series["IPv4"].Points.DataBindXY(this.xaxisValues2, this.yaxisValues2);
                this.chart1.Series["IPv6"].Points.DataBindXY(this.xaxisValues3, this.yaxisValues3);
            }
        }
    }
}
